import { cloudService } from './index'
import { IAssetRecord } from '@/types/asset'

export const addAssetApi = (asset: IAssetRecord): Promise<boolean> =>
  cloudService({
    url: '/home-api/asset',
    method: 'post',
    data: asset
  })

export const updateAssetApi = (id: number, asset: IAssetRecord): Promise<boolean> =>
  cloudService({
    url: `/home-api/asset/${id}`,
    method: 'put',
    data: asset
  })

export const deleteAssetApi = (id: number): Promise<boolean> =>
  cloudService({
    url: `/home-api/asset/${id}`,
    method: 'delete'
  })

export const queryAssetApi = (category: string): Promise<IAssetRecord[]> =>
  cloudService({
    url: '/home-api/asset',
    method: 'get',
    params: { category }
  })

export const queryAssetCategoryApi = (): Promise<string[]> =>
  cloudService({
    url: '/home-api/asset/category',
    method: 'get'
  })
